﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Blam_Unity.Classes.Engine.Halo_AA.Theater
{
    static class readPlayerChunkData
    {
        /// <summary>
        /// Read the gamertag from the selected player chunk
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <param name="selectedGTString">Gamertag string to save into the Player Chunk</param>
        /// <returns></returns>
        public static string readGamertag(MojosIO mio, int selectedNodeOffset, string selectedGTString)
        {
            mio.Position = selectedNodeOffset;
            selectedGTString = mio.ReadString(0x20, Encoding.Unicode);
            return selectedGTString.TrimEnd(' ');
        }

        /// <summary>
        /// Read the servicetag from the selected player chunk
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <param name="selectedGTString">Service Tag string to save into the Player Chunk</param>
        /// <returns></returns>
        public static string readServiceTag(MojosIO mio, int selectedNodeOffset, string selectedSTString)
        {
            mio.Position = selectedNodeOffset + 0x44;
            selectedSTString = mio.ReadString(0x08, Encoding.Unicode);
            return selectedSTString.TrimEnd(' ');
        }

        /// <summary>
        /// Read the helmet varient base ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readHelmetVarientBase(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x37;
            return convertByteToHelmetVarientID(mio.ReadByte());
        }

        /// <summary>
        /// Read the helmet varient attached to the base ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readHelmetVarientAttachment(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x37;
            return convertByteToHelmetAttachmentID(mio.ReadByte());
        }

        /// <summary>
        /// Read the chest base ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readChestID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x3A;
            return convertByteToChestID(mio.ReadByte());
        }

        /// <summary>
        /// Read the wrist Attachment ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readWristID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x3B;
            return convertByteToWristID(mio.ReadByte());
        }

        /// <summary>
        /// Read the Right Sholder ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readSholderRightID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x39;
            return convertByteToSholderID(mio.ReadByte());
        }

        /// <summary>
        /// Read the Left Sholder ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readSholderLeftID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x38;
            return convertByteToSholderID(mio.ReadByte());
        }

        /// <summary>
        /// Read the Knee Guard Attachment ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readKneeGuardID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x3D;
            return convertByteToKneeGuardID(mio.ReadByte());
        }

        /// <summary>
        /// Read the Visor Colour ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readVisorColourID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x2A;
            return convertByteToVisorColourID(mio.ReadByte());
        }

        /// <summary>
        /// Read the Armour Effect ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readArmourEffectID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x3F;
            return convertByteToArmorEffectID(mio.ReadByte());
        }

        /// <summary>
        /// Read the Utility Attachment ID
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readUtilityID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x3C;
            return convertByteToUtilityID(mio.ReadByte());
        }

        /// <summary>
        /// Read the Primary Colour Index
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readColourPrimaryID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x28;
            return convertByteToColourID(mio.ReadByte());
        }

        /// <summary>
        /// Read the Secondary Colour Index
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffset">Offset stating the start of the current Player Block</param>
        /// <returns></returns>
        public static int readColourSecondaryID(MojosIO mio, int selectedNodeOffset)
        {
            mio.Position = selectedNodeOffset + 0x29;
            return convertByteToColourID(mio.ReadByte());
        }

        #region getListBoxIndex
        private static int convertByteToChestID(byte chestID)
        {
            string chestISS = chestID.ToString();

            if (chestISS == "0") { return 0; }
            else if (chestISS == "3") { return 1; }
            else if (chestISS == "4") { return 2; }
            else if (chestISS == "5") { return 3; }
            else if (chestISS == "19") { return 4; }
            else if (chestISS == "6") { return 5; }
            else if (chestISS == "7") { return 6; }
            else if (chestISS == "8") { return 7; }
            else if (chestISS == "9") { return 8; }
            else if (chestISS == "10") { return 9; }
            else if (chestISS == "11") { return 10; }
            else if (chestISS == "12") { return 11; }
            else if (chestISS == "13") { return 12; }
            else if (chestISS == "15") { return 13; }
            else if (chestISS == "16") { return 14; }
            else if (chestISS == "17") { return 15; }
            else if (chestISS == "18") { return 16; }
            return 0;
        }

        private static int convertByteToWristID(byte wristID)
        {
            string wristISS = wristID.ToString();

            if (wristISS == "0") { return 0; }
            else if (wristISS == "1") { return 1; }
            else if (wristISS == "2") { return 2; }
            else if (wristISS == "3") { return 3; }
            else if (wristISS == "4") { return 5; }
            else if (wristISS == "5") { return 4; }
            return 0;
        }

        private static int convertByteToSholderID(byte sholderID)
        {
            string sholderISS = sholderID.ToString();

            if (sholderISS == "0") { return 0; }
            else if (sholderISS == "1") { return 1; }
            else if (sholderISS == "2") { return 2; }
            else if (sholderISS == "3") { return 3; }
            else if (sholderISS == "4") { return 4; }
            else if (sholderISS == "5") { return 5; }
            else if (sholderISS == "6") { return 6; }
            else if (sholderISS == "7") { return 7; }
            else if (sholderISS == "8") { return 8; }
            else if (sholderISS == "17") { return 9; }
            else if (sholderISS == "9") { return 10; }
            else if (sholderISS == "10") { return 11; }
            else if (sholderISS == "11") { return 12; }
            else if (sholderISS == "12") { return 13; }
            else if (sholderISS == "13") { return 14; }
            else if (sholderISS == "14") { return 15; }
            else if (sholderISS == "15") { return 16; }
            else if (sholderISS == "16") { return 17; }
            return 0;
        }

        private static int convertByteToKneeGuardID(byte kneeID)
        {
            string kneeISS = kneeID.ToString();

            if (kneeISS == "0") { return 0; }
            else if (kneeISS == "1") { return 1; }
            else if (kneeISS == "2") { return 2; }
            else if (kneeISS == "3") { return 3; }
            return 0;
        }

        private static int convertByteToVisorColourID(byte visorID)
        {
            string visorISS = visorID.ToString();

            if (visorISS == "0") { return 0; }
            else if (visorISS == "1") { return 1; }
            else if (visorISS == "2") { return 2; }
            else if (visorISS == "3") { return 3; }
            else if (visorISS == "4") { return 4; }
            return 0;
        }

        private static int convertByteToArmorEffectID(byte ArmorEffectID)
        {
            string ArmorEffectISS = ArmorEffectID.ToString();

            if (ArmorEffectISS == "0") { return 0; }
            else if (ArmorEffectISS == "1") { return 1; }
            else if (ArmorEffectISS == "2") { return 2; }
            else if (ArmorEffectISS == "3") { return 3; }
            else if (ArmorEffectISS == "4") { return 4; }
            else if (ArmorEffectISS == "5") { return 5; }
            else if (ArmorEffectISS == "6") { return 6; }
            return 0;
        }

        private static int convertByteToUtilityID(byte UtilityID)
        {
            string UtilityISS = UtilityID.ToString();

            if (UtilityISS == "0") { return 0; }
            else if (UtilityISS == "1") { return 1; }
            else if (UtilityISS == "2") { return 2; }
            else if (UtilityISS == "3") { return 3; }
            else if (UtilityISS == "4") { return 4; }
            else if (UtilityISS == "5") { return 5; }
            return 0;
        }

        private static int convertByteToColourID(byte colourID)
        {
            string colourISS = colourID.ToString();
            return Convert.ToInt16(colourISS);
        }

        private static int convertByteToHelmetVarientID(byte helmetID)
        {
            string helmetISS = helmetID.ToString();

            Forms.Halo_AA.Theater.frmCONFilm frm = new Forms.Halo_AA.Theater.frmCONFilm();

            frm.lBHelmetAttachment.Items.Clear();

            if (helmetISS == "0" || helmetISS == "1" || helmetISS == "2")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "UA", "UA/HUL" });
                return 0;
            }
            else if (helmetISS == "3" || helmetISS == "4" || helmetISS == "5")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "CBRN", "UA/HUL" });
                return 1;
            }
            else if (helmetISS == "6" || helmetISS == "7" || helmetISS == "8")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "Unk", "Unk" });
                return 2; //Unknown Helmet
            }
            else if (helmetISS == "9" || helmetISS == "10" || helmetISS == "11")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "UA/CNM", "CBRN/HUL" });
                return 3;
            }
            else if (helmetISS == "12" || helmetISS == "13" || helmetISS == "14")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "CBRN/HUL", "CNM-I" });
                return 4;
            }
            else if (helmetISS == "15" || helmetISS == "16" || helmetISS == "17")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "CNM", "UA/HUL" });
                return 5;
            }
            else if (helmetISS == "18" || helmetISS == "19" || helmetISS == "20")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "UA/HUL", "CNM" });
                return 6;
            }
            else if (helmetISS == "21" || helmetISS == "22" || helmetISS == "23")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "UA", "UA/FC" });
                return 7;
            }
            else if (helmetISS == "24" || helmetISS == "25" || helmetISS == "26")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "UA/CNM", "FC-I" });
                return 8;
            }
            else if (helmetISS == "27" || helmetISS == "28" || helmetISS == "29")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "HU/RA", "CBRN/CNM" });
                return 9;
            }
            else if (helmetISS == "30" || helmetISS == "31" || helmetISS == "32")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "CNM", "UA/HUL[3]" });
                return 10;
            }
            else if (helmetISS == "33" || helmetISS == "34" || helmetISS == "35")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "HUL-I", "UA" });
                return 11;
            }
            else if (helmetISS == "36" || helmetISS == "37" || helmetISS == "38")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "CBRN/CNM", "UA/FC-I[2]" });
                return 12;
            }
            else if (helmetISS == "39" || helmetISS == "40" || helmetISS == "41")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "CNM", "UA" });
                return 13;
            }
            else if (helmetISS == "42" || helmetISS == "43" || helmetISS == "44" || helmetISS == "45")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "HUL[3]", "UA/HUL[3]", "Haunted!" });
                return 14;
            }
            else if (helmetISS == "46" || helmetISS == "47" || helmetISS == "48")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "UA/HUL", "CBRN/CNM" });
                return 15;
            }
            else if (helmetISS == "49" || helmetISS == "50" || helmetISS == "51")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "FC-I[2]", "UA/HUL-I" });
                return 16;
            }
            else if (helmetISS == "52" || helmetISS == "53" || helmetISS == "54")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "Unk", "Unk" });
                return 17; //Unknown Helmet
            }
            else if (helmetISS == "55" || helmetISS == "56" || helmetISS == "57")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "HU/RA", "CBRN" });
                return 18;
            }
            else if (helmetISS == "58" || helmetISS == "59" || helmetISS == "60")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "HUL", "UA/HUL[3]" });
                return 19;
            }
            else if (helmetISS == "61" || helmetISS == "62" || helmetISS == "63")
            {
                frm.lBHelmetAttachment.Items.AddRange(new Object[] { "Base", "CNM", "UA/HUL[3]" });
                return 20;
            }

            return Convert.ToInt16(helmetISS);
        }

        private static int convertByteToHelmetAttachmentID(byte helmetID)
        {
            string helmetISS = helmetID.ToString();

            if (helmetISS == "0" || helmetISS == "1" || helmetISS == "2")
            {
                if (helmetISS == "0") { return 0; }
                else if (helmetISS == "1") { return 1; }
                else if (helmetISS == "2") { return 2; }
                return 0;
            }
            else if (helmetISS == "3" || helmetISS == "4" || helmetISS == "5")
            {
                if (helmetISS == "3") { return 0; }
                else if (helmetISS == "4") { return 1; }
                else if (helmetISS == "5") { return 2; }
                return 0;
            }
            else if (helmetISS == "6" || helmetISS == "7" || helmetISS == "8")
            {
                return 2; //Unknown Helmet
            }
            else if (helmetISS == "9" || helmetISS == "10" || helmetISS == "11")
            {
                if (helmetISS == "9") { return 0; }
                else if (helmetISS == "10") { return 1; }
                else if (helmetISS == "11") { return 2; }
                return 0;
            }
            else if (helmetISS == "12" || helmetISS == "13" || helmetISS == "14")
            {
                if (helmetISS == "12") { return 0; }
                else if (helmetISS == "13") { return 1; }
                else if (helmetISS == "14") { return 2; }
                return 0;
            }
            else if (helmetISS == "15" || helmetISS == "16" || helmetISS == "17")
            {
                if (helmetISS == "15") { return 0; }
                else if (helmetISS == "16") { return 1; }
                else if (helmetISS == "17") { return 2; }
                return 0;
            }
            else if (helmetISS == "18" || helmetISS == "19" || helmetISS == "20")
            {
                if (helmetISS == "18") { return 0; }
                else if (helmetISS == "19") { return 1; }
                else if (helmetISS == "20") { return 2; }
                return 0;
            }
            else if (helmetISS == "21" || helmetISS == "22" || helmetISS == "23")
            {
                if (helmetISS == "21") { return 0; }
                else if (helmetISS == "22") { return 1; }
                else if (helmetISS == "23") { return 2; }
                return 0;
            }
            else if (helmetISS == "24" || helmetISS == "25" || helmetISS == "26")
            {
                if (helmetISS == "24") { return 0; }
                else if (helmetISS == "25") { return 1; }
                else if (helmetISS == "26") { return 2; }
                return 0;
            }
            else if (helmetISS == "27" || helmetISS == "28" || helmetISS == "29")
            {
                if (helmetISS == "27") { return 0; }
                else if (helmetISS == "28") { return 1; }
                else if (helmetISS == "29") { return 2; }
                return 0;
            }
            else if (helmetISS == "30" || helmetISS == "31" || helmetISS == "32")
            {
                if (helmetISS == "30") { return 0; }
                else if (helmetISS == "31") { return 1; }
                else if (helmetISS == "32") { return 2; }
                return 0;
            }
            else if (helmetISS == "33" || helmetISS == "34" || helmetISS == "35")
            {
                if (helmetISS == "33") { return 0; }
                else if (helmetISS == "34") { return 1; }
                else if (helmetISS == "35") { return 2; }
                return 0;
            }
            else if (helmetISS == "36" || helmetISS == "37" || helmetISS == "38")
            {
                if (helmetISS == "36") { return 0; }
                else if (helmetISS == "37") { return 1; }
                else if (helmetISS == "38") { return 2; }
                return 0;
            }
            else if (helmetISS == "39" || helmetISS == "40" || helmetISS == "41")
            {
                if (helmetISS == "39") { return 0; }
                else if (helmetISS == "40") { return 1; }
                else if (helmetISS == "41") { return 2; }
                return 0;
            }
            else if (helmetISS == "42" || helmetISS == "43" || helmetISS == "44" || helmetISS == "45")
            {
                if (helmetISS == "42") { return 0; }
                else if (helmetISS == "43") { return 1; }
                else if (helmetISS == "44") { return 2; }
                else if (helmetISS == "45") { return 3; }
                return 0;
            }
            else if (helmetISS == "46" || helmetISS == "47" || helmetISS == "48")
            {
                if (helmetISS == "46") { return 0; }
                else if (helmetISS == "47") { return 1; }
                else if (helmetISS == "48") { return 2; }
                return 0;
            }
            else if (helmetISS == "49" || helmetISS == "50" || helmetISS == "51")
            {
                if (helmetISS == "49") { return 0; }
                else if (helmetISS == "50") { return 1; }
                else if (helmetISS == "51") { return 2; }
                return 0;
            }
            else if (helmetISS == "52" || helmetISS == "53" || helmetISS == "54")
            {
                return 17; //Unknown Helmet
            }
            else if (helmetISS == "55" || helmetISS == "56" || helmetISS == "57")
            {
                if (helmetISS == "55") { return 0; }
                else if (helmetISS == "56") { return 1; }
                else if (helmetISS == "57") { return 2; }
                return 0;
            }
            else if (helmetISS == "58" || helmetISS == "59" || helmetISS == "60")
            {
                if (helmetISS == "58") { return 0; }
                else if (helmetISS == "59") { return 1; }
                else if (helmetISS == "60") { return 2; }
                return 0;
            }
            else if (helmetISS == "61" || helmetISS == "62" || helmetISS == "63")
            {
                if (helmetISS == "61") { return 0; }
                else if (helmetISS == "62") { return 1; }
                else if (helmetISS == "63") { return 2; }
                return 0;
            }

            return Convert.ToInt16(helmetISS);
        }
        #endregion
    }

    static class savePlayerChunkData
    {
        /// <summary>
        /// Save all data to the selected Player Chunk
        /// </summary>
        /// <param name="mio">Mojos IO already declared</param>
        /// <param name="selectedNodeOffsets">Offset stating the start of the current Player Block</param>
        /// <param name="firstNodeSelected">see if the current chunk is the first selected player chunk</param>
        /// <param name="gamertag">Player Chunk Gamertag</param>
        /// <param name="serviceTag">Player Chunk Service Tag</param>
        /// <param name="lBHelmetAttachment">Helmet Attachment</param>
        /// <param name="lBHelmets">Helmet Base</param>
        /// <param name="lBChest">Chest Base</param>
        /// <param name="lBRSholder">Right Sholder Attachment</param>
        /// <param name="lBLSholder">Left Sholder Attachment</param>
        /// <param name="lBWrist">Wrist Attachment</param>
        /// <param name="lBKneeGuard">Knee Guard Attachment</param>
        /// <param name="lBVisorColour">Visor Colour</param>
        /// <param name="lBArmorEffect">Armour Effect</param>
        public static void savePlayerDataChunk(MojosIO mio, int selectedNodeOffsets, bool firstNodeSelected, string gamertag, string serviceTag, ListBox lBHelmetAttachment, ListBox lBHelmets, ListBox lBChest, ListBox lBRSholder, ListBox lBLSholder, ListBox lBWrist, ListBox lBKneeGuard, ListBox lBVisorColour, ListBox lBArmorEffect, ListBox lBPrimaryColour, ListBox lBSecondaryColour)
        {
            if (firstNodeSelected == false) { }
            else
            {
                //Write Gamertag
                ///Instance 1
                mio.Position = selectedNodeOffsets;
                mio.WriteString("                ", Encoding.Unicode);
                mio.Position = selectedNodeOffsets;
                mio.WriteString(gamertag, Encoding.Unicode);
                ///Instance 2
                mio.Position = selectedNodeOffsets + 0xB8;
                mio.WriteString("                ", Encoding.Unicode);
                mio.Position = selectedNodeOffsets + 0xB8;
                mio.WriteString(gamertag, Encoding.Unicode);

                //Write Service Tag
                mio.Position = selectedNodeOffsets + 0x44;
                mio.WriteString("    ", Encoding.Unicode);
                mio.Position = selectedNodeOffsets + 0x44;
                mio.WriteString(serviceTag.ToUpper(), Encoding.Unicode);

                //Write Helmet
                int helmetID = retConvertByteToHelmetID(lBHelmets.SelectedIndex);
                helmetID = helmetID + (lBHelmetAttachment.SelectedIndex);
                byte helmetsID = Convert.ToByte(helmetID);
                mio.Position = selectedNodeOffsets + 0x37;
                mio.Write(helmetsID);

                //Write Chest
                mio.Position = selectedNodeOffsets + 0x3A;
                mio.Write(retConvertByteToChestID(lBChest.SelectedIndex));

                //Wrists
                mio.Position = selectedNodeOffsets + 0x3B;
                mio.Write(retConvertByteToWristID(lBWrist.SelectedIndex));

                //Sholders
                ///Right Sholder
                mio.Position = selectedNodeOffsets + 0x39;
                mio.Write(retConvertByteToSholderID(lBRSholder.SelectedIndex));
                ///Left Sholder
                mio.Position = selectedNodeOffsets + 0x38;
                mio.Write(retConvertByteToSholderID(lBLSholder.SelectedIndex));

                //Write Knee Guards
                mio.Position = selectedNodeOffsets + 0x3D;
                mio.Write(Convert.ToByte(lBKneeGuard.SelectedIndex));

                //Write Visor Colours
                mio.Position = selectedNodeOffsets + 0x2A;
                mio.Write(Convert.ToByte(lBVisorColour.SelectedIndex));

                //Write Armor Effect
                mio.Position = selectedNodeOffsets + 0x3F;
                mio.Write(Convert.ToByte(lBArmorEffect.SelectedIndex));

                //Write Utility
                mio.Position = selectedNodeOffsets + 0x3C;
                mio.Write(Convert.ToByte(lBKneeGuard.SelectedIndex));

                //Armour Colours
                ///Primary
                mio.Position = selectedNodeOffsets + 0x28;
                mio.Write(Convert.ToByte(lBPrimaryColour.SelectedIndex));
                ///Secondary
                mio.Position = selectedNodeOffsets + 0x29;
                mio.Write(Convert.ToByte(lBSecondaryColour.SelectedIndex));
            }
        }

        #region retrieveListBoxIndex
        private static int retConvertByteToHelmetID(int helmetID)
        {
            if (helmetID == 0) { return 0; }
            else if (helmetID == 1) { return 3; }
            else if (helmetID == 2) { return 6; }
            else if (helmetID == 3) { return 9; }
            else if (helmetID == 4) { return 12; }
            else if (helmetID == 5) { return 15; }
            else if (helmetID == 6) { return 18; }
            else if (helmetID == 7) { return 21; }
            else if (helmetID == 8) { return 24; }
            else if (helmetID == 9) { return 27; }
            else if (helmetID == 10) { return 30; }
            else if (helmetID == 11) { return 33; }
            else if (helmetID == 12) { return 36; }
            else if (helmetID == 13) { return 39; }
            else if (helmetID == 14) { return 42; }
            else if (helmetID == 15) { return 46; }
            else if (helmetID == 16) { return 49; }
            else if (helmetID == 17) { return 52; }
            else if (helmetID == 18) { return 55; }
            else if (helmetID == 19) { return 58; }
            else if (helmetID == 20) { return 61; }
            return 0;
        }

        private static byte retConvertByteToChestID(int chestID)
        {
            int chestISS = 0;

            if (chestID == 0) { chestISS = 0; }
            else if (chestID == 1) { chestISS = 3; }
            else if (chestID == 2) { chestISS = 4; }
            else if (chestID == 3) { chestISS = 5; }
            else if (chestID == 4) { chestISS = 19; }
            else if (chestID == 5) { chestISS = 6; }
            else if (chestID == 6) { chestISS = 7; }
            else if (chestID == 7) { chestISS = 8; }
            else if (chestID == 8) { chestISS = 9; }
            else if (chestID == 9) { chestISS = 10; }
            else if (chestID == 10) { chestISS = 11; }
            else if (chestID == 11) { chestISS = 12; }
            else if (chestID == 12) { chestISS = 13; }
            else if (chestID == 13) { chestISS = 15; }
            else if (chestID == 14) { chestISS = 16; }
            else if (chestID == 15) { chestISS = 17; }
            else if (chestID == 16) { chestISS = 18; }

            return Convert.ToByte(chestISS);
        }

        private static byte retConvertByteToWristID(int wristID)
        {
            int wristISS = 0;

            if (wristID == 0) { wristISS = 0; }
            else if (wristID == 1) { wristISS = 1; }
            else if (wristID == 2) { wristISS = 2; }
            else if (wristID == 3) { wristISS = 3; }
            else if (wristID == 4) { wristISS = 5; }
            else if (wristID == 5) { wristISS = 4; }

            return Convert.ToByte(wristISS);
        }

        private static byte retConvertByteToSholderID(int sholderID)
        {
            int sholderISS = 0;

            if (sholderID == 0) { sholderISS = 0; }
            else if (sholderID == 1) { sholderISS = 1; }
            else if (sholderID == 2) { sholderISS = 2; }
            else if (sholderID == 3) { sholderISS = 3; }
            else if (sholderID == 4) { sholderISS = 4; }
            else if (sholderID == 5) { sholderISS = 5; }
            else if (sholderID == 6) { sholderISS = 6; }
            else if (sholderID == 7) { sholderISS = 7; }
            else if (sholderID == 8) { sholderISS = 8; }
            else if (sholderID == 17) { sholderISS = 9; }
            else if (sholderID == 9) { sholderISS = 10; }
            else if (sholderID == 10) { sholderISS = 11; }
            else if (sholderID == 11) { sholderISS = 12; }
            else if (sholderID == 12) { sholderISS = 13; }
            else if (sholderID == 13) { sholderISS = 14; }
            else if (sholderID == 14) { sholderISS = 15; }
            else if (sholderID == 15) { sholderISS = 16; }
            else if (sholderID == 16) { sholderISS = 17; }

            return Convert.ToByte(sholderISS);
        }
        #endregion
    }
}
